<?php
namespace Adminx\Model;
use Think\Model;

class GoodsModel extends Model {

    protected $_validate = array (
        array('name','require','名称不能为空', 1),
        array('brandID','require','品牌不能为空', 1),
		array('carID','require','适用车型不能为空', 1),
		array('image','checkimage','请上传产品图片',1,'callback'), 
		array('content','require','介绍不能为空', 1),
    );	

    protected $_auto = array (
    	array('cid','_cid',Model::MODEL_BOTH,'callback'),
		array('path','_path',Model::MODEL_BOTH,'callback'),
		array('createTime','time',Model::MODEL_INSERT,'function'),		
		array('updateTime','time',Model::MODEL_BOTH,'function'),
		array('image','_image',Model::MODEL_BOTH,'callback'),
        array('face','_face',Model::MODEL_BOTH,'callback'),
	);

	protected function _cid(){
		$class = explode(',', I('post.cid'));
		return $class[0];
    }

    protected function _path(){
		$class = explode(',', I('post.cid'));
		return $class[1];
    }

	protected function checkImage(){
        if (I('post.image')=='') {
            return false;
        }else{
            return true;
        }
    }

    protected function _image($image){
        if ($image) {
            return implode(",", $image);
        }else{
            return '';
        }        
    }

    protected function _face($face){
        if ($face) {
            return $face;
        }else{
            $image = I('post.image');
            return $image[0];
        }        
    }

}
?>